﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
using Visifire.Charts;

namespace CPPEI.Coolzon.UI.DataPartLib
{
    public partial class DataChartAxisBase
    {
        private Axis axisX;
        protected Axis getAxisX()
        {
            axisX = new Axis();
            axisX.Enabled = AxisXEnabled;
            axisX.StartFromZero = AxisXStartFromZero;
            axisX.AxisMinimum = AxisXMinimum;
            axisX.AxisMaximum = AxisXMaximum;
            axisX.LineStyle = AxisXLineStyle;
            axisX.LineColor = AxisXLineColor == null ? null : AxisXLineColor.Brush;
            axisX.LineThickness = AxisXLineThickness;
            axisX.Title = AxisXTitle ?? "";
            axisX.TitleFontFamily = AxisXTitleFontFamily;
            axisX.TitleFontWeight = AxisXTitleFontWeight;
            axisX.TitleFontSize = AxisXTitleFontSize;
            axisX.TitleFontColor = AxisXTitleFontColor == null ? null : AxisXTitleFontColor.Brush;
            axisX.IntervalType = AxisXIntervalType;
            if (AxisXInterval != null)
                axisX.Interval = AxisXInterval;

            AxisLabels axisLabel = new AxisLabels();
            axisLabel.Enabled = AxisXLabelEnable;
            axisLabel.FontFamily = AxisXLabelFontFamily;
            axisLabel.FontWeight = AxisXLabelFontWeight;
            axisLabel.FontSize = AxisXLabelFontSize;
            if (AxisXLabelFontColor != null)
                axisLabel.FontColor = AxisXLabelFontColor == null ? null : AxisXLabelFontColor.Brush;
            axisLabel.Angle = AxisXLabelAngle;
            axisLabel.Rows = AxisXLabelRows;
            axisLabel.TextAlignment = AxisXLabelTextAlignmnet;
            if (AxisXLabelTextWrap != null && AxisXLabelTextWrap.Value >= 0 && AxisXLabelTextWrap.Value <= 1)
            {
                axisLabel.TextWrap = AxisXLabelTextWrap.Value;
            }

            axisX.AxisLabels = axisLabel;

            ChartGrid chartGrid = new ChartGrid();
            chartGrid.Enabled = AxisXChartGridEnable;
            chartGrid.LineColor = AxisXChartGridLineColor == null ? null : AxisXChartGridLineColor.Brush;
            chartGrid.LineStyle = AxisXChartGridLineStyle;
            chartGrid.LineThickness = AxisXChartGridLineThickness;
            chartGrid.InterlacedColor = AxisXChartGridInterlacedColor == null ? null : AxisXChartGridInterlacedColor.Brush;
            axisX.Grids.Add(chartGrid);

            return axisX;
        }

        private bool axisXEnabled;
        private bool axisXStartFromZero;
        private double? axisXMinimum;
        private double? axisXMaximum;
        private double? axisXInterval;
        private Visifire.Charts.LineStyles axisXLineStyle;
        private BrushEx axisXLineColor;
        private double? axisXLineThickness;
        private string axisXTitle;
        private FontFamily axisXTitleFontFamily;
        private FontWeight axisXTitleFontWeight;
        private int axisXTitleFontSize;
        private BrushEx axisXTitleFontColor;
        private IntervalTypes axisXIntervalType;

        private bool axisXLabelEnable;
        private FontFamily axisXLabelFontFamily;
        private FontWeight axisXLabelFontWeight;
        private int axisXLabelFontSize;
        private BrushEx axisXLabelFontColor;
        private double? axisXLabelAngle;
        private int axisXLabelRows;
        private TextAlignment axisXLabelTextAlignmnet;
        private double? axisXLabelTextWrap;

        private bool axisXChartGridEnable;
        private BrushEx axisXChartGridLineColor;
        private LineStyles axisXChartGridLineStyle;
        private int axisXChartGridLineThickness;
        private BrushEx axisXChartGridInterlacedColor;

        #region Axis
        [Category("X轴")]
        [DisplayName("X轴是否可用")]
        [Description("AxisXEnabled")]
        [Editor(typeof(UI.XProperty.Editors.XBooleanEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "AxisXEnabled", "是否可用")]
        public bool AxisXEnabled
        {
            get
            {
                return axisXEnabled;
            }

            set
            {
                axisXEnabled = value;
                Refresh();
            }
        }

        [Category("X轴")]
        [DisplayName("X轴是否从0开始")]
        [Description("AxisXStartFromZero")]
        [Editor(typeof(UI.XProperty.Editors.XBooleanEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "AxisXStartFromZero", "是否从0开始")]
        public bool AxisXStartFromZero
        {
            get
            {
                return axisXStartFromZero;
            }

            set
            {
                axisXStartFromZero = value;
                Refresh();
            }
        }

        [Category("X轴")]
        [DisplayName("X轴最小值")]
        [Description("AxisXMinimum")]
        [Editor(typeof(UI.XProperty.Editors.XDoubleNullEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "AxisXMinimum", "最小值")]
        public double? AxisXMinimum
        {
            get
            {
                return axisXMinimum;
            }

            set
            {
                axisXMinimum = value;
                Refresh();
            }
        }

        [Category("X轴")]
        [DisplayName("X轴最大值")]
        [Description("AxisXMaximum")]
        [Editor(typeof(UI.XProperty.Editors.XDoubleNullEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "AxisXMaximum", "最大值")]
        public double? AxisXMaximum
        {
            get
            {
                return axisXMaximum;
            }

            set
            {
                axisXMaximum = value;
                Refresh();
            }
        }

        [Category("X轴")]
        [DisplayName("X轴步长")]
        [Description("AxisXInterval")]
        [Editor(typeof(UI.XProperty.Editors.XDoubleNullEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "AxisXInterval", "步长")]
        public double? AxisXInterval
        {
            get
            {
                return axisXInterval;
            }

            set
            {
                axisXInterval = value;
                Refresh();
            }
        }

        [Category("X轴")]
        [DisplayName("X轴步长类型")]
        [Description("AxisXIntervalType")]
        [Editor(typeof(UI.DataPartLib.XProperty.Editors.XIntervalTypesEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "AxisXIntervalType", "步长类型")]
        public IntervalTypes AxisXIntervalType
        {
            get
            {
                return axisXIntervalType;
            }

            set
            {
                axisXIntervalType = value;
                Refresh();
            }
        }

        [Category("X轴")]
        [DisplayName("X轴线样式")]
        [Description("AxisXLineStyle")]
        [Editor(typeof(UI.DataPartLib.XProperty.Editors.XLineStylesEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "AxisXLineStyle", "线样式")]
        public LineStyles AxisXLineStyle
        {
            get
            {
                return axisXLineStyle;
            }

            set
            {
                axisXLineStyle = value;
                Refresh();
            }
        }

        [Category("X轴")]
        [DisplayName("X轴线颜色")]
        [Description("AxisXLineColor")]
        [Editor(typeof(UI.XProperty.Editors.XBrushEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "AxisXLineColor", "线颜色")]
        public BrushEx AxisXLineColor
        {
            get
            {
                return axisXLineColor;
            }

            set
            {
                axisXLineColor = value;
                Refresh();
            }
        }

        [Category("X轴")]
        [DisplayName("X轴线宽度")]
        [Description("AxisXLineThickness")]
        [Editor(typeof(UI.XProperty.Editors.XDoubleNullEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "AxisXLineThickness", "线宽度")]
        public double? AxisXLineThickness
        {
            get
            {
                return axisXLineThickness;
            }

            set
            {
                axisXLineThickness = value;
                Refresh();
            }
        }

        [Category("X轴")]
        [DisplayName("X轴标题")]
        [Description("AxisXTitle")]
        [Editor(typeof(UI.XProperty.Editors.XStringEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "AxisXTitle", "标题")]
        public string AxisXTitle
        {
            get
            {
                return axisXTitle;
            }

            set
            {
                axisXTitle = value;
                Refresh();
            }
        }

        [Category("X轴")]
        [DisplayName("X轴标题字体")]
        [Description("AxisXTitleFontFamily")]
        [Editor(typeof(UI.XProperty.Editors.XFontFamilyEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "AxisXTitleFontFamily", "标题字体")]
        public FontFamily AxisXTitleFontFamily
        {
            get
            {
                return axisXTitleFontFamily;
            }

            set
            {
                axisXTitleFontFamily = value;
                Refresh();
            }
        }

        [Category("X轴")]
        [DisplayName("X轴标题字体粗细")]
        [Description("AxisXTitleFontWeight")]
        [Editor(typeof(UI.XProperty.Editors.XFontWeightEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "AxisXTitleFontWeight", "标题字体粗细")]
        public FontWeight AxisXTitleFontWeight
        {
            get
            {
                return axisXTitleFontWeight;
            }

            set
            {
                axisXTitleFontWeight = value;
                Refresh();
            }
        }

        [Category("X轴")]
        [DisplayName("X轴标题字体大小")]
        [Description("AxisXTitleFontSize")]
        [Editor(typeof(UI.XProperty.Editors.XIntEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "AxisXTitleFontSize", "标题字体大小")]
        public int AxisXTitleFontSize
        {
            get
            {
                return axisXTitleFontSize;
            }

            set
            {
                axisXTitleFontSize = value;
                Refresh();
            }
        }

        [Category("X轴")]
        [DisplayName("X轴标题字体颜色")]
        [Description("AxisXTitleFontColor")]
        [Editor(typeof(UI.XProperty.Editors.XBrushEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "AxisXTitleFontColor", "标题字体颜色")]
        public BrushEx AxisXTitleFontColor
        {
            get
            {
                return axisXTitleFontColor;
            }

            set
            {
                axisXTitleFontColor = value;
                Refresh();
            }
        }
        #endregion

        #region AxisLabels
        [Category("X轴")]
        [DisplayName("X轴是否显示文本")]
        [Description("AxisXLabelEnable")]
        [Editor(typeof(UI.XProperty.Editors.XBooleanEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "AxisXLabelEnable", "是否显示文本")]
        public bool AxisXLabelEnable
        {
            get
            {
                return axisXLabelEnable;
            }

            set
            {
                axisXLabelEnable = value;
                Refresh();
            }
        }

        [Category("X轴")]
        [DisplayName("X轴文本字体")]
        [Description("AxisXLabelFontFamily")]
        [Editor(typeof(UI.XProperty.Editors.XFontFamilyEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "AxisXLabelFontFamily", "文本字体")]
        public FontFamily AxisXLabelFontFamily
        {
            get
            {
                return axisXLabelFontFamily;
            }

            set
            {
                axisXLabelFontFamily = value;
                Refresh();
            }
        }

        [Category("X轴")]
        [DisplayName("X轴文本字体粗细")]
        [Description("AxisXLabelFontWeight")]
        [Editor(typeof(UI.XProperty.Editors.XFontWeightEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "AxisXLabelFontWeight", "文本字体粗细")]
        public FontWeight AxisXLabelFontWeight
        {
            get
            {
                return axisXLabelFontWeight;
            }

            set
            {
                axisXLabelFontWeight = value;
                Refresh();
            }
        }

        [Category("X轴")]
        [DisplayName("X轴文本字体大小")]
        [Description("AxisXLabelFontSize")]
        [Editor(typeof(UI.XProperty.Editors.XIntEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "AxisXLabelFontSize", "文本字体大小")]
        public int AxisXLabelFontSize
        {
            get
            {
                return axisXLabelFontSize;
            }

            set
            {
                axisXLabelFontSize = value;
                Refresh();
            }
        }

        [Category("X轴")]
        [DisplayName("X轴文本字体颜色")]
        [Description("AxisXLabelFontColor")]
        [Editor(typeof(UI.XProperty.Editors.XBrushEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "AxisXLabelFontColor", "文本字体颜色")]
        public BrushEx AxisXLabelFontColor
        {
            get
            {
                return axisXLabelFontColor;
            }

            set
            {
                axisXLabelFontColor = value;
                Refresh();
            }
        }

        [Category("X轴")]
        [DisplayName("X轴文本倾斜角度")]
        [Description("AxisXLabelAngle")]
        [Editor(typeof(UI.XProperty.Editors.XDoubleNullEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "AxisXLabelAngle", "文本倾斜角度")]
        public double? AxisXLabelAngle
        {
            get
            {
                return axisXLabelAngle;
            }

            set
            {
                axisXLabelAngle = value;
                Refresh();
            }
        }

        [Category("X轴")]
        [DisplayName("X轴文本显示行数")]
        [Description("AxisXLabelRows")]
        [Editor(typeof(UI.XProperty.Editors.XIntEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "AxisXLabelRows", "文本显示行数")]
        public int AxisXLabelRows
        {
            get
            {
                return axisXLabelRows;
            }

            set
            {
                axisXLabelRows = value;
                Refresh();
            }
        }

        //[Category("X轴")]
        //[DisplayName("X轴文本对齐")]
        //[Description("AxisXLabelTextAlignmnet")]
        //[Editor(typeof(UI.XProperty.Editors.XTextAlignmentEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        //[XProperty(XPropertyCategory.Other, "AxisXLabelTextAlignmnet", "文本对齐")]
        public TextAlignment AxisXLabelTextAlignmnet
        {
            get
            {
                return axisXLabelTextAlignmnet;
            }

            set
            {
                axisXLabelTextAlignmnet = value;
                Refresh();
            }
        }

        //暂不使用
        //[Category("X轴")]
        //[DisplayName("X轴文本换行(0-1)")]
        //[Description("AxisXLabelTextWrap")]
        //[Editor(typeof(UI.XProperty.Editors.XDoubleEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        //[XProperty(XPropertyCategory.Other, "AxisXLabelTextWrap", "文本换行(0-1)")]
        public double? AxisXLabelTextWrap
        {
            get
            {
                return axisXLabelTextWrap;
            }

            set
            {
                axisXLabelTextWrap = value;
                Refresh();
            }
        }
        #endregion

        #region ChartGrid
        [Category("X轴")]
        [DisplayName("X轴是否网格线")]
        [Description("AxisXChartGridEnable")]
        [Editor(typeof(UI.XProperty.Editors.XBooleanEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "AxisXChartGridEnable", "是否网格线")]
        public bool AxisXChartGridEnable
        {
            get
            {
                return axisXChartGridEnable;
            }

            set
            {
                axisXChartGridEnable = value;
                Refresh();
            }
        }

        [Category("X轴")]
        [DisplayName("X轴网格线颜色")]
        [Description("AxisXChartGridLineColor")]
        [Editor(typeof(UI.XProperty.Editors.XBrushEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "AxisXChartGridLineColor", "网格线颜色")]
        public BrushEx AxisXChartGridLineColor
        {
            get
            {
                return axisXChartGridLineColor;
            }

            set
            {
                axisXChartGridLineColor = value;
                Refresh();
            }
        }

        [Category("X轴")]
        [DisplayName("X轴网格线类型")]
        [Description("AxisXChartGridLineStyle")]
        [Editor(typeof(UI.DataPartLib.XProperty.Editors.XLineStylesEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "AxisXChartGridLineStyle", "网格线类型")]
        public LineStyles AxisXChartGridLineStyle
        {
            get
            {
                return axisXChartGridLineStyle;
            }

            set
            {
                axisXChartGridLineStyle = value;
                Refresh();
            }
        }

        [Category("X轴")]
        [DisplayName("X轴网格线宽度")]
        [Description("AxisXChartGridLineThickness")]
        [Editor(typeof(UI.XProperty.Editors.XIntEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "AxisXChartGridLineThickness", "网格线宽度")]
        public int AxisXChartGridLineThickness
        {
            get
            {
                return axisXChartGridLineThickness;
            }

            set
            {
                axisXChartGridLineThickness = value;
                Refresh();
            }
        }

        [Category("X轴")]
        [DisplayName("X轴网格线间隔颜色")]
        [Description("AxisXChartGridInterlacedColor")]
        [Editor(typeof(UI.XProperty.Editors.XBrushEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "AxisXChartGridInterlacedColor", "网格线间隔颜色")]
        public BrushEx AxisXChartGridInterlacedColor
        {
            get
            {
                return axisXChartGridInterlacedColor;
            }

            set
            {
                axisXChartGridInterlacedColor = value;
                Refresh();
            }
        }
        #endregion

        private int? _XXValueNLCC;
        [Category("X轴")]
        [DisplayName("X轴x轴一行显示字符数")]
        [Description("XXValueNLCC")]
        [Editor(typeof(UI.XProperty.Editors.XIntEditor), typeof(UI.XProperty.XPropertyValueEditor))]
        [XProperty(XPropertyCategory.Other, "XXValueNLCC", "x轴一行显示字符数")]
        public int? XXValueNLCC
        {
            get
            {
                return _XXValueNLCC;
            }
            set
            {
                _XXValueNLCC = value;
                Refresh();
            }
        }
    }
}
